-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: set limits for maximum memory use. #4147
Conversation
The latest in the 4.x series.
WIP: Currently hardcoded to 8 GB.
Related research note: The other mechanism Linux provides for setting these sorts of constraints is through cgroups (Control Groups). But I think |
If the process would otherwise exceed this limit, will it just crash, or will Java try garbage-collection? |
If the program is allocating memory on the heap and there's not enough free space within the maximum heap size set ( The process limits should be set higher than that max JVM heap size. In testing this I've seen Java throw an OutOfMemoryError sometimes, but other times it's not been so descriptive. It probably depends on if the thing failing to allocate the memory is Java or if it's in native code (e.g. LWJGL or OpenAL). |
The JNA in jopenvr was removed in #4169, clearing the way for this. It also upgraded JNA so this PR can drop that part. But since this adds command-line options, I'll say it's blocked by #4157. It's not technically blocked but I'd rather get picocli merged first and then switch this to use picocli, as opposed to making the picocli PR do more work for this one. |
unblocked!!! now that #4157 gave us a better way to add command-line args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a few finishing touches, but it's working as expected.
implementation(platform("org.junit:junit-bom:5.7.1")) { | ||
// junit-bom will set version numbers for the other org.junit dependencies. | ||
} | ||
implementation("org.junit.jupiter:junit-jupiter-api") | ||
implementation("org.junit.jupiter:junit-jupiter-params") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIXME: these are supposed to be test dependencies!
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class DataSizeConverter implements CommandLine.ITypeConverter<Long> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIXME: docstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've had some memory leaks where the game seems to take up far more of the system's memory than the amount allowed for Java's maximum heap size.
This uses some operating-system-specific functions to set limits on how much memory the process can allocate.
Because this is so system-dependent, I'm introducing this as a developer/debugger feature rather than intending it for production use.
(Players won't want the game taking runaway amounts of memory either, but getting consistent support for this and setting expectations for how it works would be a bigger project. Possibly would want to do it in Launcher, as some of these controls are better set before even launching the process.)
Contains
Linux support only.
oom_score_adj
to give the out-of-memory reaper encouragement to choose this process for termination when the system is out of memory as a whole.How to test
On Linux:
check
/proc/PID/limits
On other platforms:
Outstanding before merging